var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CurrentPage:1,
    PayCreditLogList:[],
    loadingMoreHidden:false,
    PayCredits:0,
    PayCreditName:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.GetCredits()
    this.setData({
      PayCredits: options.PayCredits,
      PayCreditName:options.PayCreditName
    })
    wx.setNavigationBarTitle({
      title: options.PayCreditName
    })
  },
  //获取积分记录
  GetCredits:function(){
    var that = this;
    wx.request({
      url: app.globalData.host + '/api/User/PayCreditLog?type=2',
      data: {
        uid: app.globalData.userInfo.Uid,
        page: that.data.CurrentPage,
      },
      success: function (res) {
        console.log("获取积分记录");
        console.log(res);
        if(res.data.Code == 0){
          var caseArry = res.data.Data.PayCreditLogList
            if (that.data.CurrentPage != 1) {
              var preGoods = that.data.PayCreditLogList
              caseArry = preGoods.concat(caseArry);
          }
          that.setData({
            PayCreditLogList: caseArry,
            loadingMoreHidden: res.data.Data.PageModel.HasNextPage
          })
        }
        else{
          wx.showModal({
            title: '提示',
            content: res.data.errMsg,
            showCancel: false
          })
          return;
        }
      }
    })
  },
  // 加载更多
  loadMore: function (e) {
    var that = this;
    if (!that.data.loadingMoreHidden) return;
    var currPage = that.data.CurrentPage;
    that.setData({
      CurrentPage: currPage + 1
    })
    that.GetCredits();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})